package Test1.PTZ;

import Test1.HCNetSDK;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;

/**
 * Created by panting6 on 2021/4/2.
 */
public class PTZAbsoluteEX {
    static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;

    public void ptzAbsoluteEX(int lUserID, int iChannelNum)
    {
        IntByReference pchannel = new IntByReference(iChannelNum);
        Pointer pChannelNum = pchannel.getPointer();

        HCNetSDK.NET_DVR_STD_CONFIG lpConfigParam6697 = new HCNetSDK.NET_DVR_STD_CONFIG();
        HCNetSDK.NET_DVR_PTZABSOLUTEEX_CFG lpPTZAbsoluteEX_cfgInfo = new HCNetSDK.NET_DVR_PTZABSOLUTEEX_CFG();
        lpConfigParam6697.lpCondBuffer = pChannelNum;
        lpConfigParam6697.dwCondSize = 4;
        HCNetSDK.BYTE_ARRAY m_szStatusBuf = new HCNetSDK.BYTE_ARRAY(4096 * 4);
        lpConfigParam6697.lpStatusBuffer = m_szStatusBuf.getPointer();
        lpConfigParam6697.dwStatusSize = 4096 * 4;
        lpPTZAbsoluteEX_cfgInfo.dwSize = lpPTZAbsoluteEX_cfgInfo.size();
        lpPTZAbsoluteEX_cfgInfo.struPTZCtrl.fPan = (float) 202.81;
        lpPTZAbsoluteEX_cfgInfo.struPTZCtrl.fTilt = (float) -15.34;
        lpPTZAbsoluteEX_cfgInfo.struPTZCtrl.fZoom = (float) 1;
        lpPTZAbsoluteEX_cfgInfo.struPTZCtrl.dwFocus = 399;
        lpPTZAbsoluteEX_cfgInfo.dwFocalLen = 1250;
        lpPTZAbsoluteEX_cfgInfo.fHorizontalSpeed = (float)10;
        lpPTZAbsoluteEX_cfgInfo.fVerticalSpeed = (float)10;
        lpPTZAbsoluteEX_cfgInfo.byZoomType = 0;
        lpPTZAbsoluteEX_cfgInfo.write();
        lpConfigParam6697.lpInBuffer = lpPTZAbsoluteEX_cfgInfo.getPointer();
        lpConfigParam6697.dwInSize = lpPTZAbsoluteEX_cfgInfo.dwSize;
        lpConfigParam6697.write();
        if(!hCNetSDK.NET_DVR_SetSTDConfig(lUserID,6697,lpConfigParam6697))
        {
            System.out.println( "设置高精度PTZ参数失败，错误号：" + hCNetSDK.NET_DVR_GetLastError());
        }
        else{
            System.out.println( "设置高精度PTZ参数成功");
        }


        HCNetSDK.NET_DVR_STD_CONFIG lpConfigParam6696 = new HCNetSDK.NET_DVR_STD_CONFIG();
        HCNetSDK.NET_DVR_PTZABSOLUTEEX_CFG lpPTZAbsoluteEX_cfg = new HCNetSDK.NET_DVR_PTZABSOLUTEEX_CFG();


        lpConfigParam6696.lpCondBuffer = pChannelNum;
        lpConfigParam6696.dwCondSize = 4;
        lpConfigParam6696.lpInBuffer = null;
        lpConfigParam6696.dwInSize = 0;
        lpConfigParam6696.lpOutBuffer = lpPTZAbsoluteEX_cfg.getPointer();
        lpConfigParam6696.dwOutSize = lpPTZAbsoluteEX_cfg.size();
        lpConfigParam6696.write();

        if(!hCNetSDK.NET_DVR_GetSTDConfig(lUserID,HCNetSDK.NET_DVR_GET_PTZABSOLUTEEX,lpConfigParam6696))
        {
            System.out.println( "获取高精度PTZ绝对位置配置失败，错误号：" + hCNetSDK.NET_DVR_GetLastError());
        }
        else
        {
           lpPTZAbsoluteEX_cfg.read();
            System.out.println("P：" + lpPTZAbsoluteEX_cfg.struPTZCtrl.fPan + " T：" + lpPTZAbsoluteEX_cfg.struPTZCtrl.fTilt + " Z：" + lpPTZAbsoluteEX_cfg.struPTZCtrl.fZoom
            + " 聚焦参数：" + lpPTZAbsoluteEX_cfg.struPTZCtrl.dwFocus + " 聚焦范围：" + lpPTZAbsoluteEX_cfg.dwFocalLen + " 水平转动速度：" + lpPTZAbsoluteEX_cfg.fHorizontalSpeed
                    + " 垂直转动速度：" + lpPTZAbsoluteEX_cfg.fVerticalSpeed + " 镜头变倍配置类型：" + lpPTZAbsoluteEX_cfg.byZoomType);
        }
    }
}
